<?php
namespace Home\Model;
use Think\Model\RelationModel;
class DomainTransdetailModel extends  RelationModel 
{
    
    protected $_auto = array (
        array('createdate','date',1,'function',array('Y-m-d H:i:s')),
    );
    
    
	protected $_link = array(
                'DomainTranslog'=>array(
                    'mapping_type'=> self::BELONGS_TO,
                    'mapping_name'=> 'translog',
                    'class_name'=> 'DomainTranslog',
                    'foreign_key'=>'logid'
                ),
        	    'UserDomains'=>array(
        	        'mapping_type'=> self::BELONGS_TO,
        	        'mapping_name'=> 'userDomain',
        	        'class_name'=> 'UserDomains',
        	        'foreign_key'=>'domain_id'
        	    ),
        	    'DomainType'=>array(
        	        'mapping_type'=> self::BELONGS_TO,
        	        'mapping_name'=> 'domainType',
        	        'class_name'=> 'DomainType',
        	        'foreign_key'=>'domain_type_id'
        	    ),
    );
    
    
    protected $_validate = array(
        array('logid','require','域名批量交易ID不能为空！'), 
        array('domain_id','require','用户域名ID不能为空！'), 
        array('price','require','成交价不能为空！'),
        array('domain','require','域名不能为空！'),
        array('trans_type',array(1,2),'交易类型值范围不正确！',1,'in'), 
    );
    
    /**
     * 插入用户交易记录
     * @param unknown $arry
     * @return number|unknown
     */
    public function inst($arry)
    {
        foreach ($arry as $key => $value){
            $data[$key] = $value;
        };
        $result["status"]=0;
        if (!$this->create($data)){
            $result["mess"]=$this->getError();
        }else{
            $result = $this->add(); // 写入数据到数据库
            if($result){
                $result["status"]=1;
                $result["mess"]=$result;
            }
        };
        return $result;
    }
    
    /**
     * 查询用户域名交易记录
     * @param  $arry
     * @return 
     */
	public function getList($arry)
	{  
		foreach ($arry as $key => $value){
		    if($key == "uid"){
		        $uid = $value;
		    };
		    if($key == "uid"){
		        $timeType = $value;
		    };
	    };
	    $con1['buyerid'] =array('eq', $uid);
	    $con1['sellerid'] =array('eq', $uid);
	    $con1['_logic'] = 'or';
	    $con2['_complex'] = $con2;
		foreach ($arry as $key => $value){
		    if($key != "uid"){
		        $con2[$key] = array('eq', $value);
		    };
	    };
        return $this->relation(true)->where($con2)->select();
	}
	
	/**
	 * 查询查询用户域名交易记录数量
	 * @param unknown $arry
	 * @return mixed|boolean|string|NULL|unknown|object
	 */
	public function getCount($arry)
	{
	    foreach ($arry as $key => $value){
		    if($key == "uid"){
		        $uid = $value;
		    };
	    };
	    $con1['buyerid'] =array('eq', $uid);
	    $con1['sellerid'] =array('eq', $uid);
	    $con1['_logic'] = 'or';
	    $con2['_complex'] = $con2;
		foreach ($arry as $key => $value){
		    if($key != "uid"){
		        $con2[$key] = array('eq', $value);
		    };
	    };
	    return $this->where($con2)->count();
	}
}
?>